import { icepick } from "@/icepick-client";
import { weather, time, holiday, summary } from "@/tools";
import z from "zod";

const {{pascalCase name}}AgentInput = z.object({
  message: z.string(),
});

const {{pascalCase name}}AgentOutput = z.object({
  message: z.string(),
  highlights: z.array(z.string()).optional(),
  recommendations: z.array(z.string()).optional(),
});

export const {{camelCase name}}Toolbox = icepick.toolbox({
  tools: [weather, time, holiday, summary],
});

export const {{camelCase name}}Agent = icepick.agent({
  name: "{{kebabCase name}}-agent",
  executionTimeout: "1m",
  inputSchema: {{pascalCase name}}AgentInput,
  outputSchema: {{pascalCase name}}AgentOutput,
  description: "A {{name}} agent to get weather, time, and holiday information with rich formatting",
  fn: async (input, ctx) => {
    const result = await {{camelCase name}}Toolbox.pickAndRun({
      prompt: input.message,
    });

    let geoData: any = {};

    switch (result.name) {
      case "weather":
        geoData.weather = result.output;
        break;
      case "time":
        geoData.time = result.output;
        break;
      case "holiday":
        geoData.holiday = result.output;
        break;
      case "summary":
        return {
          message: result.output.formattedResponse,
          highlights: result.output.highlights,
          recommendations: result.output.recommendations,
        };
      default:
        return {{camelCase name}}Toolbox.assertExhaustive(result);
    }

    // Use summary tool to format the response nicely
    const summaryResult = await summary.run({
      data: geoData,
      userQuery: input.message
    });

    return {
      message: summaryResult.formattedResponse,
      highlights: summaryResult.highlights,
      recommendations: summaryResult.recommendations,
    };
  },
});
